home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / src_1218.zip / AX25MAIL.C < prev    next >
C/C++ Source or Header  |  1991-06-01  |  2KB  |  112 lines

  1. /* AX25 mailbox interface
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  *
  4.  *    May '91    Bill Simpson
  5.  *        move to separate file for compilation & linking
  6.  */
  7. #include "global.h"
  8. #include "proc.h"
  9. #include "ax25.h"
  10. #include "socket.h"
  11. #include "session.h"
  12. #include "mailbox.h"
  13. #include "ax25mail.h"
  14.  
  15.  
  16. /* Axi_sock is kept in Socket.c, so that this module won't be called */
  17.  
  18. int
  19. ax25start(argc,argv,p)
  20. int argc;
  21. char *argv[];
  22. void *p;
  23. {
  24.     int s,type;
  25.  
  26.     if (Axi_sock != -1)
  27.         return 0;
  28.  
  29.     psignal(Curproc,0);    /* Don't keep the parser waiting */
  30.     chname(Curproc,"AX25 listener");
  31.     Axi_sock = socket(AF_AX25,SOCK_STREAM,0);
  32.     /* bind() is done automatically */
  33.     if(listen(Axi_sock,1) == -1){
  34.         close_s(Axi_sock);
  35.         return -1;
  36.     }
  37.     for(;;){
  38.         if((s = accept(Axi_sock,NULLCHAR,NULLINT)) == -1)
  39.             break;    /* Service is shutting down */
  40.  
  41.         type = AX25TNC;
  42.         /* Eat the line that triggered the connection
  43.          * and then start the mailbox
  44.          */
  45.         sockmode(s,SOCK_ASCII);    /* To make recvline work */
  46.         recvline(s,NULLCHAR,80); 
  47.         newproc("mbox",2048,mbx_incom,s,(void *)type,NULL,0);
  48.     }
  49.     close_s(Axi_sock);
  50.     Axi_sock = -1;
  51.     return 0;
  52. }
  53. int
  54. ax250(argc,argv,p)
  55. int argc;
  56. char *argv[];
  57. void *p;
  58. {
  59.     close_s(Axi_sock);
  60.     Axi_sock = -1;
  61.     return 0;
  62. }
  63.  
  64.  
  65. int
  66. dogateway(argc,argv,p)
  67. int argc;
  68. char *argv[];
  69. void *p;
  70. {
  71.     struct mbx *m;
  72.     struct sockaddr_ax fsocket;
  73.     int ndigis,i,s;
  74.     char digis[MAXDIGIS][AXALEN];
  75.     char target[AXALEN];
  76.  
  77.     m = (struct mbx *)p;
  78.     if(!(m->privs & AX25_CMD)){
  79.         tprintf(Noperm);
  80.         return 0;
  81.     }
  82.     /* If digipeaters are given, put them in the routing table */
  83.     if(argc > 3){
  84.         setcall(target,argv[2]);
  85.         ndigis = argc - 3;
  86.         if(ndigis > MAXDIGIS){
  87.             tprintf("Too many digipeaters\n");
  88.             return 1;
  89.         }
  90.         for(i=0;i<ndigis;i++){
  91.             if(setcall(digis[i],argv[i+3]) == -1){
  92.                 tprintf("Bad digipeater %s\n",argv[i+3]);
  93.                 return 1;
  94.             }
  95.         }
  96.         if(ax_add(target,AX_LOCAL,digis,ndigis) == NULLAXR){
  97.             tprintf("Route add failed\n");
  98.             return 1;
  99.         }
  100.     }
  101.     if((s = socket(AF_AX25,SOCK_STREAM,0)) == -1){
  102.         tprintf(Nosock);
  103.         return 0;
  104.     }
  105.     fsocket.sax_family = AF_AX25;
  106.     setcall(fsocket.ax25_addr,argv[2]);
  107.     strncpy(fsocket.iface,argv[1],ILEN);
  108.     m->startmsg = mallocw(80);
  109.     sprintf(m->startmsg,"*** LINKED to %s\n",m->name);
  110.     return gw_connect(m,s,(char *)&fsocket, sizeof(struct sockaddr_ax));
  111. }
  112.